package Classes.GameViews.ViewCartoonTargets// ActionScript file
{
	import Classes.GameViews.GameView;
	import Classes.Interfaces.I_NeedUpdatePaperMan;
	
	import MV_BMP.MovieClip_BMP;
	
	import flash.display.Sprite;

	/**
	 *动画对象类 
	 * @author upstream
	 * 
	 */	
	public class ViewCartoonTarget extends GameView
	{
		public static var scaleValue:Number=0.6;
		private var _cartoonsObj:Object;/*动画存储器*/
		private var _nowPlayingName:String;/*当前播放动画名*/
		public function ViewCartoonTarget():void
		{
			this.init();
		}
		
		private function init():void
		{

		}
		
		/**
		 *设定动画数据 
		 * @param cartoonsObj
		 * @param updateSign
		 * 
		 */		
		protected function setCartoons(cartoonsObj:Object,updateSign:Boolean=false):void
		{
			this._cartoonsObj=cartoonsObj;
			if(updateSign)this.updateCartoon();
		}
		
		/**
		 *更新动画
		 * 
		 */		
		private function updateCartoon():void
		{
			if(this.numChildren>0)
			{
			    var nowPlayingMC:MovieClip_BMP=(this.getChildAt(0)) as MovieClip_BMP;
			    var nowFrame:int=nowPlayingMC.currentFrame;
			    var isStop:Boolean=nowPlayingMC.isStop;
			    this.playCartoon(this.nowPlayingName,this.isMirror,nowFrame,isStop);
			}
		}
		
		/**
		 *播放动作
		 * @param actionName 行为名
		 * @param frame 帧数
		 * @param isStop 是否停止
		 * 
		 */		
		public function playCartoon(cartoonName:String,isMirror:Boolean=false,frame:int=1,isStop:Boolean=false):void
		{
			while(this.numChildren>0)
			{
				(this.getChildAt(0) as MovieClip_BMP).stop();
				this.removeChildAt(0);
			}
			var cartoonObj:Object=this.cartoonsObj[cartoonName];
			if(!cartoonObj)throw new Error("该动画不存在");
			var cartoonMC:MovieClip_BMP=cartoonObj.cartoon;
			cartoonMC.gotoAndPlay(frame);
			if(isStop)cartoonMC.stop();
			this.addChild(cartoonMC);
			cartoonMC.x=-cartoonObj.setX;
			cartoonMC.y=-cartoonObj.setY;
			this.scaleX=isMirror?-1:1;
			this.nowPlayingName=cartoonName;
		}
		
		public function release():void
		{
			while(this.numChildren)this.removeChildAt(0);
			while(this.parent)this.parent.removeChild(this);
			this._cartoonsObj=null;
		}

		/*getter & setter*/
		public function get cartoonsObj():Object
		{
			return _cartoonsObj;
		}
		
		public function get nowPlayingName():String
		{
			return _nowPlayingName;
		}

		public function set nowPlayingName(value:String):void
		{
			_nowPlayingName = value;
		}
		
		public function get isMirror():Boolean
		{
			return (this.scaleX==-1)?true:false;
		}


	}
}